package com.zyx.crawlerdemo.httpclient.httpclient.ssl;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.ParseException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.util.EntityUtils;

/**
 * @author Yaxi.Zhang
 * @since 2021/8/11 17:30
 * desc: 简单的TLS验证
 */
public class TlsClient {
    public static void main(String[] args) throws ParseException, IOException {
        String url = "https://cn.kompass.com/a/hospitality-tourism-hotel-and-catering-industries/78/";
        // 实例化
        SslClient sslClient = new SslClient();
        HttpClient httpClientSsl = sslClient.initSslClient("TLS");
        HttpGet httpGet = new HttpGet(url);
        //获取结果
        HttpResponse httpResponse = null;
        try {
            httpResponse = httpClientSsl.execute(httpGet);
        } catch (IOException e) {
            e.printStackTrace();
        }
        // 状态码200表示响应成功
        if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            //获取实体内容
            String entity = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
            //输出实体内容
            System.out.println(entity);
        }
        // 消耗实体
        EntityUtils.consume(httpResponse.getEntity());
    }
}
